package com.gitee.hermer.engine.jars.demo.boot;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.Ordered;

import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.jc.dsmclient.v2.c3p0.AlogPooledDataSource;

@Configuration
@PropertySource(EngineConstant.MYSQLDB_CONFIG_PROPERTIES_CLASS_PATH)
@ComponentScan(basePackages={"com.gitee.hermer.engine.jars.dependent.dsm","com.gitee.hermer.engine.jars.dependent.xa.datasource"})
public class MysqlDBConfig implements Ordered{
	
	@Value("${mysql.dataSourceName}")
	private String dataSourceName;

	@Bean(destroyMethod="close")
	public DataSource dataSource() {
		AlogPooledDataSource dataSource = new AlogPooledDataSource();
		dataSource.setDataSourceName(dataSourceName);
		return dataSource;
	}

	@Override
	public int getOrder() {
		return Ordered.HIGHEST_PRECEDENCE+500;
	}
}
